﻿/*
* Sale_order_sheet.cs
*
* 功 能： N/A
* 类 名： Sale_order_sheet
*
* Ver    变更日期             负责人     变更内容
* ───────────────────────────────────
* V1.0  2016-03-08 08:53:11    黄润伟    
*
* Copyright © 2015 www.xhdcrm.com All rights reserved.
*┌──────────────────────────────────┐
*│　版权所有：小黄豆                      　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using XHD.DBUtility;//Please add references
namespace XHD.DAL
{
    /// <summary>
	/// 数据访问类:Sale_order_sheet
	/// </summary>
	public partial class Sale_order_sheet
    {
        public Sale_order_sheet()
        { }

        #region  BasicMethod
        
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(XHD.Model.Sale_order_sheet model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Sale_order_sheet(");
            strSql.Append("id,xhs_batch,xhs_cuskind,xhs_website,xhs_code,xhs_nickname,xhs_fun,xhs_praise,xhs_gaofei,xhs_product,xhs_follower,xhs_pr,xhs_state,xhs_publishlink,xhs_remark,xhs_adr,xhs_consignee,xhs_shouhuotel,xhs_checkrepeat,xhs_checkcode,xhs_checkpublish,wx_username,ali_alipaycode,xhs_expressid,xhs_express,create_id,create_time,xhs_settlestate,xhs_article_code)");
            strSql.Append(" values (");
            strSql.Append("@id,@xhs_batch,@xhs_cuskind,@xhs_website,@xhs_code,@xhs_nickname,@xhs_fun,@xhs_praise,@xhs_gaofei,@xhs_product,@xhs_follower,@xhs_pr,xhs_state,@xhs_publishlink,@xhs_remark,@xhs_adr,@xhs_consignee,@xhs_shouhuotel,@xhs_checkrepeat,@xhs_checkcode,@xhs_checkpublish,@wx_username,@ali_alipaycode,@xhs_expressid,@xhs_express,@create_id,@create_time,@xhs_settlestate,@xhs_article_code)");
            SqlParameter[] parameters = {
                    new SqlParameter( "@id", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_batch", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_cuskind", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_website", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_code", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_nickname", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_fun", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_praise", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_gaofei", SqlDbType.Decimal,9),
                    new SqlParameter( "@xhs_product", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_follower", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_pr", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_state", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_publishlink", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_remark", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_adr", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_consignee", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_shouhuotel", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_checkrepeat", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_checkcode", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_checkpublish", SqlDbType.Int,4),
                    new SqlParameter( "@wx_username", SqlDbType.VarChar,500),
                    new SqlParameter( "@ali_alipaycode", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_expressid", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_express", SqlDbType.VarChar,500),
                    new SqlParameter( "@create_id", SqlDbType.VarChar,500),
                    new SqlParameter( "@create_time", SqlDbType.DateTime),
                    new SqlParameter( "@xhs_settlestate", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_article_code", SqlDbType.VarChar,500)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.xhs_batch;
            parameters[2].Value = model.xhs_cuskind;
            parameters[3].Value = model.xhs_website;
            parameters[4].Value = model.xhs_code;
            parameters[5].Value = model.xhs_nickname;
            parameters[6].Value = model.xhs_fun;
            parameters[7].Value = model.xhs_praise;
            parameters[8].Value = model.xhs_gaofei;
            parameters[9].Value = model.xhs_product;
            parameters[10].Value = model.xhs_follower;
            parameters[11].Value = model.xhs_pr;
            parameters[12].Value = model.xhs_state;
            parameters[13].Value = model.xhs_publishlink;
            parameters[14].Value = model.xhs_remark;
            parameters[15].Value = model.xhs_adr;
            parameters[16].Value = model.xhs_consignee;
            parameters[17].Value = model.xhs_shouhuotel;
            parameters[18].Value = model.xhs_checkrepeat;
            parameters[19].Value = model.xhs_checkcode;
            parameters[20].Value = model.xhs_checkpublish;
            parameters[21].Value = model.wx_username;
            parameters[22].Value = model.ali_alipaycode;
            parameters[23].Value = model.xhs_expressid;
            parameters[24].Value = model.xhs_express;
            parameters[25].Value = model.xhs_settlestate;
            parameters[26].Value = model.xhs_article_code;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            return rows > 0 ? true : false;
        }

        /// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XHD.Model.Sale_order_sheet model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Sale_order_sheet set ");
            //strSql.Append("product_id=@product_id,");
            //strSql.Append("agio=@agio,");
            //strSql.Append("quantity=@quantity,");
            //strSql.Append("amount=@amount");
            //strSql.Append(" where id=@id ");
            strSql.Append("xhs_batch = @xhs_batch,");
            strSql.Append("xhs_cuskind = @xhs_cuskind,");
            strSql.Append("xhs_website = @xhs_website,");
            strSql.Append("xhs_code = @xhs_code,");
            strSql.Append("xhs_nickname = @xhs_nickname,");
            strSql.Append("xhs_fun = @xhs_fun,");
            strSql.Append("xhs_praise = @xhs_praise,");
            strSql.Append("xhs_gaofei = @xhs_gaofei,");
            strSql.Append("xhs_product = @xhs_product,");
            strSql.Append("xhs_follower = @xhs_follower,");
            strSql.Append("xhs_pr = @xhs_pr,");
            strSql.Append("xhs_state = @xhs_state,");
            strSql.Append("xhs_publishlink = @xhs_publishlink,");
            strSql.Append("xhs_remark = @xhs_remark,");
            strSql.Append("xhs_adr = @xhs_adr,");
            strSql.Append("xhs_consignee = @xhs_consignee,");
            strSql.Append("xhs_shouhuotel = @xhs_shouhuotel,");
            strSql.Append("xhs_checkrepeat = @xhs_checkrepeat,");
            strSql.Append("xhs_checkcode = @xhs_checkcode,");
            strSql.Append("xhs_checkpublish = @xhs_checkpublish,");
            strSql.Append("wx_username = @wx_username,");
            strSql.Append("ali_alipaycode = @ali_alipaycode,");
            strSql.Append("xhs_expressid = @xhs_expressid,");
            strSql.Append("xhs_express = @xhs_express,");
            strSql.Append("xhs_settlestate = @xhs_settlestate,");
            strSql.Append("xhs_article_code = @xhs_article_code ");

            strSql.Append(" where id=@id ");

            SqlParameter[] parameters = {

                    new SqlParameter( "@xhs_batch", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_cuskind", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_website", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_code", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_nickname", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_fun", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_praise", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_gaofei", SqlDbType.Decimal,9),
                    new SqlParameter( "@xhs_product", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_follower", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_pr", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_state", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_publishlink", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_remark", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_adr", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_consignee", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_shouhuotel", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_checkrepeat", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_checkcode", SqlDbType.Int,4),
                    new SqlParameter( "@xhs_checkpublish", SqlDbType.Int,4),
                    new SqlParameter( "@wx_username", SqlDbType.VarChar,500),
                    new SqlParameter( "@ali_alipaycode", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_expressid", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_express", SqlDbType.VarChar,500),
                    new SqlParameter( "@xhs_settlestate", SqlDbType.VarChar, 500),
                    new SqlParameter( "@xhs_article_code", SqlDbType.VarChar, 500),
                    new SqlParameter( "@id", SqlDbType.VarChar,500)
            };

            parameters[0].Value = model.xhs_batch;
            parameters[1].Value = model.xhs_cuskind;
            parameters[2].Value = model.xhs_website;
            parameters[3].Value = model.xhs_code;
            parameters[4].Value = model.xhs_nickname;
            parameters[5].Value = model.xhs_fun;
            parameters[6].Value = model.xhs_praise;
            parameters[7].Value = model.xhs_gaofei;
            parameters[8].Value = model.xhs_product;
            parameters[9].Value = model.xhs_follower;
            parameters[10].Value = model.xhs_pr;
            parameters[11].Value = model.xhs_state;
            parameters[12].Value = model.xhs_publishlink;
            parameters[13].Value = model.xhs_remark;
            parameters[14].Value = model.xhs_adr;
            parameters[15].Value = model.xhs_consignee;
            parameters[16].Value = model.xhs_shouhuotel;
            parameters[17].Value = model.xhs_checkrepeat;
            parameters[18].Value = model.xhs_checkcode;
            parameters[19].Value = model.xhs_checkpublish;
            parameters[20].Value = model.wx_username;
            parameters[21].Value = model.ali_alipaycode;
            parameters[22].Value = model.xhs_expressid;
            parameters[23].Value = model.xhs_express;
            parameters[24].Value = model.xhs_settlestate;
            parameters[25].Value = model.xhs_article_code;

            parameters[24].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            return rows > 0 ? true : false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string whereStr)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Sale_order_sheet ");
            strSql.Append(" where "+whereStr);
           
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            return rows > 0 ? true : false;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere, bool isAll = false )
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  ");
            strSql.Append("Sale_order_sheet.[id] ");
            strSql.Append(",Sale_order_sheet.[xhs_batch] ");
            strSql.Append(",Sale_order_sheet.[xhs_cuskind] ");
            strSql.Append(",Sale_order_sheet.[xhs_website] ");
            strSql.Append(",Sale_order_sheet.[xhs_code] ");
            strSql.Append(",Sale_order_sheet.[xhs_nickname] ");
            strSql.Append(",Sale_order_sheet.[xhs_fun] ");
            strSql.Append(",Sale_order_sheet.[xhs_praise] ");
            strSql.Append(",Sale_order_sheet.[xhs_gaofei] ");
            strSql.Append(",Sale_order_sheet.[xhs_product] ");
            strSql.Append(",Sale_order_sheet.[xhs_follower] ");
            strSql.Append(",Sale_order_sheet.[xhs_pr] ");
            strSql.Append(",xhs_state=ISNULL((SELECT params_name FROM Sys_param WHERE id=Sale_order_sheet.[xhs_state]),'') ");
            strSql.Append(",Sale_order_sheet.[xhs_publishlink] ");
            strSql.Append(",Sale_order_sheet.[xhs_remark] ");
            strSql.Append(",Sale_order_sheet.[xhs_adr] ");
            strSql.Append(",Sale_order_sheet.[xhs_consignee] ");
            strSql.Append(",Sale_order_sheet.[xhs_shouhuotel] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkrepeat] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkcode] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkpublish] ");
            strSql.Append(",Sale_order_sheet.[wx_username] ");
            strSql.Append(",Sale_order_sheet.[ali_alipaycode] ");
            strSql.Append(",Sale_order_sheet.[xhs_expressid] ");
            strSql.Append(",Sale_order_sheet.[xhs_express] ");
            strSql.Append(",xhs_settlestate=ISNULL((SELECT params_name FROM Sys_param WHERE id=Sale_order_sheet.[xhs_settlestate]),'') ");
            strSql.Append(",Sale_order_sheet.[xhs_article_code] ");
            strSql.Append("FROM [dbo].[Sale_order_sheet] ");

            if (!isAll) strSql.Append("  INNER JOIN CRM_Customer ON CRM_Customer.xhs_code = Sale_order_sheet.xhs_code ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder, bool isAll = false)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append("Sale_order_sheet.[id] ");
            strSql.Append(",Sale_order_sheet.[xhs_batch] ");
            strSql.Append(",Sale_order_sheet.[xhs_cuskind] ");
            strSql.Append(",Sale_order_sheet.[xhs_website] ");
            strSql.Append(",Sale_order_sheet.[xhs_code] ");
            strSql.Append(",Sale_order_sheet.[xhs_nickname] ");
            strSql.Append(",Sale_order_sheet.[xhs_fun] ");
            strSql.Append(",Sale_order_sheet.[xhs_praise] ");
            strSql.Append(",Sale_order_sheet.[xhs_gaofei] ");
            strSql.Append(",Sale_order_sheet.[xhs_product] ");
            strSql.Append(",Sale_order_sheet.[xhs_follower] ");
            strSql.Append(",Sale_order_sheet.[xhs_pr] ");
            strSql.Append(",xhs_state=ISNULL((SELECT params_name FROM Sys_param WHERE id=Sale_order_sheet.[xhs_state]),'') ");
            strSql.Append(",Sale_order_sheet.[xhs_publishlink] ");
            strSql.Append(",Sale_order_sheet.[xhs_remark] ");
            strSql.Append(",Sale_order_sheet.[xhs_adr] ");
            strSql.Append(",Sale_order_sheet.[xhs_consignee] ");
            strSql.Append(",Sale_order_sheet.[xhs_shouhuotel] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkrepeat] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkcode] ");
            strSql.Append(",Sale_order_sheet.[xhs_checkpublish] ");
            strSql.Append(",Sale_order_sheet.[wx_username] ");
            strSql.Append(",Sale_order_sheet.[ali_alipaycode] ");
            strSql.Append(",Sale_order_sheet.[xhs_expressid] ");
            strSql.Append(",Sale_order_sheet.[xhs_express] ");
            strSql.Append(",xhs_settlestate=ISNULL((SELECT params_name FROM Sys_param WHERE id=Sale_order_sheet.[xhs_settlestate]),'') ");
            strSql.Append(",Sale_order_sheet.[xhs_article_code] ");

            strSql.Append("FROM [dbo].[Sale_order_sheet] ");

            strSql.Append("FROM[dbo].[Sale_order_sheet] ");
            if (!isAll) strSql.Append(" INNER JOIN CRM_Customer ON CRM_Customer.xhs_code = Sale_order_sheet.xhs_code ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

